﻿using System.Data;
using BookTheBook.Data.NameDefinitions;
using Migrator.Framework;

namespace BookTheBook.Migrations
{
    [Migration(6)]
    public class _006_NewTableRoleToUser : Migration
    {
        public override void Up()
        {
            Database.AddTable(TableNames.RoleToUser, 
                                    new Column(ColumnNames.RoleId, DbType.Int32, ColumnProperty.PrimaryKey),
                                    new Column(ColumnNames.UserId, DbType.Int32, ColumnProperty.PrimaryKey));

            Database.AddForeignKey(ForeignKeyNames.RoleToUser, 
                                       TableNames.RoleToUser, ColumnNames.RoleId,
                                       TableNames.Role, ColumnNames.RoleId);

            Database.AddForeignKey(ForeignKeyNames.UserToRole, 
                                       TableNames.RoleToUser, ColumnNames.UserId,
                                       TableNames.User, ColumnNames.UserId);
            
        }

        public override void Down()
        {
            Database.RemoveForeignKey(TableNames.RoleToUser, ForeignKeyNames.RoleToUser);
            Database.RemoveForeignKey(TableNames.RoleToUser, ForeignKeyNames.UserToRole);
            Database.RemoveTable(TableNames.RoleToUser);
        }
    }
}
